﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.ResourcesManagement;
using System.Globalization;
using System.Runtime.Serialization;

namespace YasharEl.Infrastructure.ProcessEngine
{
    [Serializable]
    public class CouldNotReadWorkflowProgramException : TranslatedDomainModelException
    {
        #region Constants

        private const string CouldNotReadWorkflowProgram = "CouldNotReadWorkflowProgram";

        #endregion

        #region ReadOnly Fields

        private readonly string _workflowPath;
        private readonly Exception _innerException;

        #endregion

        #region Properties

        public string WorkflowPath
        {
            get { return _workflowPath; }
        }

        public Exception InnerWorkflowException
        {
            get { return _innerException; }
        }

        #endregion

        #region Constructors

        public CouldNotReadWorkflowProgramException(IResourceManager resourceManager, string workflowPath, Exception innerException)
            : base
             (
                resourceManager,
                string.Format(
                    resourceManager.GetString(CouldNotReadWorkflowProgram, CultureInfo.GetCultureInfo("en")),
                    workflowPath
                ),
                innerException
             )
        {
            _workflowPath = workflowPath;
            _innerException = innerException;
        }

        public CouldNotReadWorkflowProgramException(IResourceManager resourceManager, string workflowPath)
            : base
             (
                resourceManager,
                string.Format(
                    resourceManager.GetString(CouldNotReadWorkflowProgram, CultureInfo.GetCultureInfo("en")),
                    workflowPath
                )
             )
        {
            _workflowPath = workflowPath;
        }

        protected CouldNotReadWorkflowProgramException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        #endregion

        #region TranslatedDomainModelException Implementation

        protected override string ExceptionMessageResourceKey
        {
            get { return CouldNotReadWorkflowProgram; }
        }

        public override string TranslatedMessage
        {
            get
            {
                return string.Format(resourceManager.GetString(CouldNotReadWorkflowProgram), WorkflowPath);
            }
        }

        #endregion
    }
}
